package ui.commands;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.handlers.HandlerUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class SwitchPerspectiveCommand extends AbstractHandler {//implements ISelectionListener{
	private final static Logger logger = 
		LoggerFactory.getLogger(SwitchPerspectiveCommand.class);
	
	private TableViewer tableViewer;
	private String perspectiveId;

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		
		perspectiveId = event.getParameter("switch.perspectiveId");
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
		IWorkbench bench =window.getWorkbench();
		try {
			bench.showPerspective(perspectiveId, window);
			
//			bench.showPerspective(IPartId.ProductPerspective, window);
		} catch (WorkbenchException e) {
			// TODO Auto-generated catch block
			logger.error("Exception in the SwitchPerspective");
		}
		return null;
	}
	
//	@Override
//	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
//		logger.debug("selection Change");
//		if (selection instanceof IStructuredSelection) {
//			logger.debug("selection Change2");
//			if( selection instanceof EgnProduct){
//				logger.debug("selection Change3");
//				perspectiveId = IPartId.ProductPerspective;
//			}
//		}
//	}
}
